<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.jpg">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.jpg">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha256-AbA177XfpSnFEvgpYu1jMygiLabzPCJCRIBtR5jGc0k=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"example.com","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.13.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"manual","top_n_per_article":1,"unescape":false,"preload":true}}</script><script src="/js/config.js"></script>

    <meta name="description" content="帮助启动类命令启动docker1systemctl start docker  停止docker1systemctl stop docker  重启docker1systemctl restart docker  查看docker状态1systemctl status docker  开机启动1systemctl enable docker  查看docker概要信息1docker info  查">
<meta property="og:type" content="article">
<meta property="og:title" content="docker常用命令">
<meta property="og:url" content="http://example.com/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/index.html">
<meta property="og:site_name" content="陈树立的博客">
<meta property="og:description" content="帮助启动类命令启动docker1systemctl start docker  停止docker1systemctl stop docker  重启docker1systemctl restart docker  查看docker状态1systemctl status docker  开机启动1systemctl enable docker  查看docker概要信息1docker info  查">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_images.png">
<meta property="og:image" content="http://example.com/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_search.png">
<meta property="og:image" content="http://example.com/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_search_desc.png">
<meta property="og:image" content="http://example.com/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_df.png">
<meta property="og:image" content="http://example.com/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_run.png">
<meta property="article:published_time" content="2022-09-06T09:04:05.000Z">
<meta property="article:modified_time" content="2022-10-21T09:16:15.680Z">
<meta property="article:author" content="chenshuli">
<meta property="article:tag" content="docker">
<meta property="article:tag" content="容器化">
<meta property="article:tag" content="虚拟化">
<meta property="article:tag" content="devops">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_images.png">


<link rel="canonical" href="http://example.com/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://example.com/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/","path":"2022/09/06/云原生/docker/docker常用命令/","title":"docker常用命令"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>docker常用命令 | 陈树立的博客</title>
  






  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">陈树立的博客</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li><li class="menu-item menu-item-commonweal"><a href="/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B8%AE%E5%8A%A9%E5%90%AF%E5%8A%A8%E7%B1%BB%E5%91%BD%E4%BB%A4"><span class="nav-number">1.</span> <span class="nav-text">帮助启动类命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%90%AF%E5%8A%A8docker"><span class="nav-number">1.1.</span> <span class="nav-text">启动docker</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%81%9C%E6%AD%A2docker"><span class="nav-number">1.2.</span> <span class="nav-text">停止docker</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%87%8D%E5%90%AFdocker"><span class="nav-number">1.3.</span> <span class="nav-text">重启docker</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8Bdocker%E7%8A%B6%E6%80%81"><span class="nav-number">1.4.</span> <span class="nav-text">查看docker状态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%BC%80%E6%9C%BA%E5%90%AF%E5%8A%A8"><span class="nav-number">1.5.</span> <span class="nav-text">开机启动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8Bdocker%E6%A6%82%E8%A6%81%E4%BF%A1%E6%81%AF"><span class="nav-number">1.6.</span> <span class="nav-text">查看docker概要信息</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8Bdocker%E6%80%BB%E4%BD%93%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3"><span class="nav-number">1.7.</span> <span class="nav-text">查看docker总体帮助文档</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8Bdocker%E5%91%BD%E4%BB%A4%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3"><span class="nav-number">1.8.</span> <span class="nav-text">查看docker命令帮助文档</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%95%9C%E5%83%8F%E5%91%BD%E4%BB%A4"><span class="nav-number">2.</span> <span class="nav-text">镜像命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%97%E5%87%BA%E6%9C%AC%E5%9C%B0%E4%B8%BB%E6%9C%BA%E4%B8%8A%E7%9A%84%E9%95%9C%E5%83%8F"><span class="nav-number">2.1.</span> <span class="nav-text">列出本地主机上的镜像</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E8%AF%A2%E6%9F%90%E4%B8%AA%E9%95%9C%E5%83%8F"><span class="nav-number">2.2.</span> <span class="nav-text">查询某个镜像</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B8%8B%E8%BD%BD%E9%95%9C%E5%83%8F"><span class="nav-number">2.3.</span> <span class="nav-text">下载镜像</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E9%95%9C%E5%83%8F-x2F-%E5%AE%B9%E5%99%A8-x2F-%E6%95%B0%E6%8D%AE%E5%8D%B7%E6%89%80%E5%8D%A0%E7%9A%84%E7%A9%BA%E9%97%B4"><span class="nav-number">2.4.</span> <span class="nav-text">查看镜像&#x2F;容器&#x2F;数据卷所占的空间</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E9%95%9C%E5%83%8F"><span class="nav-number">2.5.</span> <span class="nav-text">删除镜像</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%B9%E5%99%A8%E5%91%BD%E4%BB%A4"><span class="nav-number">3.</span> <span class="nav-text">容器命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%97%E5%87%BA%E5%BD%93%E5%89%8D%E6%89%80%E6%9C%89%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C%E7%9A%84%E5%AE%B9%E5%99%A8"><span class="nav-number">3.1.</span> <span class="nav-text">列出当前所有正在运行的容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%96%B0%E5%BB%BA%E5%90%AF%E5%8A%A8%E5%AE%B9%E5%99%A8"><span class="nav-number">3.2.</span> <span class="nav-text">新建启动容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BF%9B%E5%85%A5%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C%E7%9A%84%E5%AE%B9%E5%99%A8"><span class="nav-number">3.3.</span> <span class="nav-text">进入正在运行的容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%80%80%E5%87%BA%E5%AE%B9%E5%99%A8"><span class="nav-number">3.4.</span> <span class="nav-text">退出容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%90%AF%E5%8A%A8%E5%B7%B2%E5%81%9C%E6%AD%A2%E8%BF%90%E8%A1%8C%E7%9A%84%E5%AE%B9%E5%99%A8"><span class="nav-number">3.5.</span> <span class="nav-text">启动已停止运行的容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%87%8D%E5%90%AF%E5%AE%B9%E5%99%A8"><span class="nav-number">3.6.</span> <span class="nav-text">重启容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%81%9C%E6%AD%A2%E5%AE%B9%E5%99%A8"><span class="nav-number">3.7.</span> <span class="nav-text">停止容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%BC%BA%E5%88%B6%E5%81%9C%E6%AD%A2%E5%AE%B9%E5%99%A8"><span class="nav-number">3.8.</span> <span class="nav-text">强制停止容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E5%AE%B9%E5%99%A8"><span class="nav-number">3.9.</span> <span class="nav-text">删除容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8%E6%97%A5%E5%BF%97"><span class="nav-number">3.10.</span> <span class="nav-text">查看容器日志</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8%E5%86%85%E8%BF%90%E8%A1%8C%E7%9A%84%E8%BF%9B%E7%A8%8B"><span class="nav-number">3.11.</span> <span class="nav-text">查看容器内运行的进程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8%E5%86%85%E9%83%A8%E7%BB%86%E8%8A%82"><span class="nav-number">3.12.</span> <span class="nav-text">查看容器内部细节</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%8E%E5%AE%B9%E5%99%A8%E5%86%85%E6%8B%B7%E8%B4%9D%E6%96%87%E4%BB%B6%E5%88%B0%E5%AE%BF%E4%B8%BB%E6%9C%BA"><span class="nav-number">3.13.</span> <span class="nav-text">从容器内拷贝文件到宿主机</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AF%BC%E5%85%A5%E5%AE%B9%E5%99%A8"><span class="nav-number">3.14.</span> <span class="nav-text">导入容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AF%BC%E5%87%BA%E5%AE%B9%E5%99%A8"><span class="nav-number">3.15.</span> <span class="nav-text">导出容器</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="chenshuli"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">chenshuli</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">12</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/chenshuli88" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;chenshuli88" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="/wangyicsl@126.com" title="E-Mail → wangyicsl@126.com"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="chenshuli">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="陈树立的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="docker常用命令 | 陈树立的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          docker常用命令
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-09-06 17:04:05" itemprop="dateCreated datePublished" datetime="2022-09-06T17:04:05+08:00">2022-09-06</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2022-10-21 17:16:15" itemprop="dateModified" datetime="2022-10-21T17:16:15+08:00">2022-10-21</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/" itemprop="url" rel="index"><span itemprop="name">云原生</span></a>
        </span>
    </span>

  
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Changyan：</span>
    
    <a title="docker常用命令" href="/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/#SOHUCS" itemprop="discussionUrl">
      <span id="sourceId::d43af808a0eae384abcba66d9f3be1e3" class="cy_cmt_count" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>2.3k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>2 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="帮助启动类命令"><a href="#帮助启动类命令" class="headerlink" title="帮助启动类命令"></a>帮助启动类命令</h2><h3 id="启动docker"><a href="#启动docker" class="headerlink" title="启动docker"></a>启动docker</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl start docker</span><br></pre></td></tr></table></figure>

<h3 id="停止docker"><a href="#停止docker" class="headerlink" title="停止docker"></a>停止docker</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl stop docker</span><br></pre></td></tr></table></figure>

<h3 id="重启docker"><a href="#重启docker" class="headerlink" title="重启docker"></a>重启docker</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart docker</span><br></pre></td></tr></table></figure>

<h3 id="查看docker状态"><a href="#查看docker状态" class="headerlink" title="查看docker状态"></a>查看docker状态</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl status docker</span><br></pre></td></tr></table></figure>

<h3 id="开机启动"><a href="#开机启动" class="headerlink" title="开机启动"></a>开机启动</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl <span class="built_in">enable</span> docker</span><br></pre></td></tr></table></figure>

<h3 id="查看docker概要信息"><a href="#查看docker概要信息" class="headerlink" title="查看docker概要信息"></a>查看docker概要信息</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker info</span><br></pre></td></tr></table></figure>

<h3 id="查看docker总体帮助文档"><a href="#查看docker总体帮助文档" class="headerlink" title="查看docker总体帮助文档"></a>查看docker总体帮助文档</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker --<span class="built_in">help</span></span><br></pre></td></tr></table></figure>

<h3 id="查看docker命令帮助文档"><a href="#查看docker命令帮助文档" class="headerlink" title="查看docker命令帮助文档"></a>查看docker命令帮助文档</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker 具体命令 --<span class="built_in">help</span></span><br></pre></td></tr></table></figure>

<h2 id="镜像命令"><a href="#镜像命令" class="headerlink" title="镜像命令"></a>镜像命令</h2><h3 id="列出本地主机上的镜像"><a href="#列出本地主机上的镜像" class="headerlink" title="列出本地主机上的镜像"></a>列出本地主机上的镜像</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br><span class="line">docker images -a  <span class="comment"># 列车本地所有的镜像（含历史映像层）</span></span><br><span class="line">docker images -q  <span class="comment"># 只显示镜像id</span></span><br></pre></td></tr></table></figure>

<img src="/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_images.png" class="" title="docker_images">

<blockquote>
<p>REPOSITORY: 表示镜像的仓库源</br><br>TAG：镜像的标签版本号</br><br>IMAGE ID: 镜像id</br><br>CREATED: 镜像创建时间</br><br>SIZE: 镜像大小</p>
</blockquote>
<h3 id="查询某个镜像"><a href="#查询某个镜像" class="headerlink" title="查询某个镜像"></a>查询某个镜像</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 在网站https://hub.docker.com/上查询镜像</span></span><br><span class="line">docker search [OPTIONS] 镜像名字   </span><br></pre></td></tr></table></figure>

<p>eg: docker search –limit 5 redis  列出5个镜像名含有redis的，limit默认25个</p>
<img src="/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_search.png" class="" title="docker_search">

<img src="/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_search_desc.png" class="" title="docker_search_desc">

<h3 id="下载镜像"><a href="#下载镜像" class="headerlink" title="下载镜像"></a>下载镜像</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull 镜像名字[:TAG]</span><br></pre></td></tr></table></figure>

<p>eg: docker pull ubuntu 没有TAG等价于 docker pull ubuntu:latest，获取最新版</p>
<h3 id="查看镜像-x2F-容器-x2F-数据卷所占的空间"><a href="#查看镜像-x2F-容器-x2F-数据卷所占的空间" class="headerlink" title="查看镜像&#x2F;容器&#x2F;数据卷所占的空间"></a>查看镜像&#x2F;容器&#x2F;数据卷所占的空间</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker system <span class="built_in">df</span></span><br></pre></td></tr></table></figure>

<img src="/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_df.png" class="" title="docker_df">

<h3 id="删除镜像"><a href="#删除镜像" class="headerlink" title="删除镜像"></a>删除镜像</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 删除单个</span></span><br><span class="line">docker rmi -f 镜像<span class="built_in">id</span></span><br><span class="line"><span class="comment"># 删除多个</span></span><br><span class="line">docker rmi -f 镜像名1:TAG  镜像名2:TAG</span><br><span class="line"><span class="comment"># 删除全部</span></span><br><span class="line">docker rmi -f $(docker images -qa)</span><br></pre></td></tr></table></figure>

<h2 id="容器命令"><a href="#容器命令" class="headerlink" title="容器命令"></a>容器命令</h2><h3 id="列出当前所有正在运行的容器"><a href="#列出当前所有正在运行的容器" class="headerlink" title="列出当前所有正在运行的容器"></a>列出当前所有正在运行的容器</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">docker ps [OPTIONS]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 列出当前所有正在运行的容器+历史上运行过的</span></span><br><span class="line">docker ps -a</span><br><span class="line"><span class="comment"># 列出最近创建的容器</span></span><br><span class="line">docker ps -l</span><br><span class="line"><span class="comment"># 列车最近创建的3个容器</span></span><br><span class="line">docker ps -n 3</span><br><span class="line"><span class="comment"># 静默模式，只显示容器编号</span></span><br><span class="line">docker ps -q</span><br></pre></td></tr></table></figure>

<h3 id="新建启动容器"><a href="#新建启动容器" class="headerlink" title="新建启动容器"></a>新建启动容器</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run [OPTIONS] IMAGE [COMMAND] [ARG...]</span><br></pre></td></tr></table></figure>

<img src="/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/docker%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/docker_run.png" class="" title="docker_run">

<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 启动后台守护式容器，容器名为mynginx，使用镜像为nginx，指定端口映射为7081，-v为目录挂载（宿主机目录:容器目录）</span></span><br><span class="line">docker run --name mynginx -p:7081:7081 \</span><br><span class="line">-v /nfs/sme/dist:/usr/share/nginx/html \</span><br><span class="line">-v /nfs/sme/nginx/:/etc/nginx  \</span><br><span class="line">-v /nfs/sme/logs:/var/log/nginx \</span><br><span class="line">-d nginx</span><br><span class="line"></span><br><span class="line"><span class="comment"># 启动前台交互式</span></span><br><span class="line">docker run -it redis:6.0.8</span><br><span class="line">docker run -it centos:6.0.8 /bin/bash</span><br></pre></td></tr></table></figure>

<h3 id="进入正在运行的容器"><a href="#进入正在运行的容器" class="headerlink" title="进入正在运行的容器"></a>进入正在运行的容器</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">1. 进入</span><br><span class="line">docker <span class="built_in">exec</span> -it 容器<span class="built_in">id</span> bashShell</span><br><span class="line"><span class="comment"># 例如 </span></span><br><span class="line">docker <span class="built_in">exec</span> -it a2b057419f1f /bin/bash</span><br><span class="line">2. 重新进入</span><br><span class="line">docker attach 容器<span class="built_in">id</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># exec和attach区别：attach直接进入容器启动命令的终端，不会启动新的进程，用exit退出，会导致容器停止。exec是在容器中打开新的终端，并且可以启动新的进程，用exit退出，不会导致容器的停止。</span></span><br></pre></td></tr></table></figure>

<h3 id="退出容器"><a href="#退出容器" class="headerlink" title="退出容器"></a>退出容器</h3><ol>
<li>exit, run进去容器，exit退出，容器停止</li>
<li>ctrl+p+q,run进去容器，ctrl+q+p退出，容器不停止</li>
</ol>
<h3 id="启动已停止运行的容器"><a href="#启动已停止运行的容器" class="headerlink" title="启动已停止运行的容器"></a>启动已停止运行的容器</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker start 容器<span class="built_in">id</span>或者容器名</span><br></pre></td></tr></table></figure>

<h3 id="重启容器"><a href="#重启容器" class="headerlink" title="重启容器"></a>重启容器</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker restart 容器<span class="built_in">id</span>或者容器名</span><br></pre></td></tr></table></figure>

<h3 id="停止容器"><a href="#停止容器" class="headerlink" title="停止容器"></a>停止容器</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker stop 容器<span class="built_in">id</span>或者容器名</span><br><span class="line"><span class="comment"># 停止所有容器</span></span><br><span class="line">docker stop $(docker ps -aq)</span><br></pre></td></tr></table></figure>

<h3 id="强制停止容器"><a href="#强制停止容器" class="headerlink" title="强制停止容器"></a>强制停止容器</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker <span class="built_in">kill</span> 容器<span class="built_in">id</span>或者容器名</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="删除容器"><a href="#删除容器" class="headerlink" title="删除容器"></a>删除容器</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 删除指定容器 </span></span><br><span class="line">docker <span class="built_in">rm</span> -f 容器<span class="built_in">id</span></span><br><span class="line"><span class="comment"># 删除未启动成功的容器</span></span><br><span class="line">docker <span class="built_in">rm</span> $(docker ps -a|grep Created|awk <span class="string">&#x27;&#123;print $1&#125;&#x27;</span>)</span><br><span class="line">或者</span><br><span class="line">docker <span class="built_in">rm</span> $(docker ps -qf status=created)</span><br><span class="line"><span class="comment"># 删除退出状态的容器</span></span><br><span class="line">docker <span class="built_in">rm</span> $(docker ps -a|grep Exited|awk <span class="string">&#x27;&#123;print $1&#125;&#x27;</span>)</span><br><span class="line">或者</span><br><span class="line">docker <span class="built_in">rm</span> $(docker ps -qf status=exited)</span><br><span class="line"><span class="comment"># 删除所有未运行的容器</span></span><br><span class="line">docker <span class="built_in">rm</span> $(docker ps -a -q)</span><br></pre></td></tr></table></figure>

<h3 id="查看容器日志"><a href="#查看容器日志" class="headerlink" title="查看容器日志"></a>查看容器日志</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker logs 容器<span class="built_in">id</span></span><br></pre></td></tr></table></figure>

<h3 id="查看容器内运行的进程"><a href="#查看容器内运行的进程" class="headerlink" title="查看容器内运行的进程"></a>查看容器内运行的进程</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker top 容器<span class="built_in">id</span></span><br></pre></td></tr></table></figure>

<h3 id="查看容器内部细节"><a href="#查看容器内部细节" class="headerlink" title="查看容器内部细节"></a>查看容器内部细节</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker inspect 容器<span class="built_in">id</span></span><br></pre></td></tr></table></figure>

<h3 id="从容器内拷贝文件到宿主机"><a href="#从容器内拷贝文件到宿主机" class="headerlink" title="从容器内拷贝文件到宿主机"></a>从容器内拷贝文件到宿主机</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker <span class="built_in">cp</span> 容器<span class="built_in">id</span>:容器内路径 宿主机路径</span><br><span class="line">eg: docker <span class="built_in">cp</span> f5fa58c8c1c4:/usr/local/test/test.txt /test/test.txt</span><br></pre></td></tr></table></figure>

<h3 id="导入容器"><a href="#导入容器" class="headerlink" title="导入容器"></a>导入容器</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 从tar包中的内容创建一个新的文件系统再导入为镜像</span></span><br><span class="line"><span class="built_in">cat</span> 文件名.tar | docker import -镜像用户/镜像名：镜像版本号</span><br><span class="line"><span class="comment"># 例如</span></span><br><span class="line"><span class="built_in">cat</span> test.tar.gz | docker import - <span class="built_in">test</span>/ubuntu:2.1</span><br></pre></td></tr></table></figure>

<h3 id="导出容器"><a href="#导出容器" class="headerlink" title="导出容器"></a>导出容器</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 导出容器的内容留作一个tar归档文件</span></span><br><span class="line">docker <span class="built_in">export</span> 容器<span class="built_in">id</span> &gt; 文件名.tar.gz</span><br><span class="line"><span class="comment"># 例如</span></span><br><span class="line">docker <span class="built_in">export</span> 61279fc3cc6a &gt; test.tar.gz</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="reward-container">
  <div></div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wechatpay.jpg" alt="chenshuli 微信">
        <span>微信</span>
      </div>
      <div>
        <img src="/images/alipay.jpg" alt="chenshuli 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>

          <div class="post-tags">
              <a href="/tags/docker/" rel="tag"># docker</a>
              <a href="/tags/%E5%AE%B9%E5%99%A8%E5%8C%96/" rel="tag"># 容器化</a>
              <a href="/tags/%E8%99%9A%E6%8B%9F%E5%8C%96/" rel="tag"># 虚拟化</a>
              <a href="/tags/devops/" rel="tag"># devops</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2022/09/06/%E4%BA%91%E5%8E%9F%E7%94%9F/docker/centos%E5%AE%89%E8%A3%85%E5%8D%B8%E8%BD%BDdocker/" rel="prev" title="centos安装卸载docker">
                  <i class="fa fa-chevron-left"></i> centos安装卸载docker
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2022/09/21/java/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B/1_JUC%E6%A6%82%E8%BF%B0/" rel="next" title="JUC概述">
                  JUC概述 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments" id="SOHUCS" sid="d43af808a0eae384abcba66d9f3be1e3"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">chenshuli</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">16k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">15 分钟</span>
  </span>
</div>

    </div>
  </footer>

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  
<script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.0/search.js" integrity="sha256-vXZMYLEqsROAXkEw93GGIvaB2ab+QW6w3+1ahD9nXXA=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>





  




<script class="next-config" data-name="changyan" type="application/json">{"enable":true,"appid":"cywgkfr9L","appkey":"045ab620a1fe071936bd2feddfbeaad8"}</script>
<script src="/js/third-party/comments/changyan.js"></script>

</body>
</html>
